﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.SysDictType.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.SysDictType;
/// <summary>
/// 添加系统字典类型服务
/// </summary>
public class InsertSysDictTypeService : ApiBase<RequestInsertSysDictTypeModel>
{
    /// <summary>
    /// 系统字典类型仓储
    /// </summary>
    public SysDictTypeRep sysDictTypeRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new SysDictTypeModel();

        model.DictName = Parameter.DictName;
        model.DictType = Parameter.DictType;
        model.Status = Parameter.Status;
        model.Remark = Parameter.Remark;
        model.CreateBy = userKey?.ToString();
        model.CreateTime= DateTime.Now;

        var res = sysDictTypeRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = sysDictTypeRep.GetSysDictTypeByDictId(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}
